<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@include file="./header.jsp" %>

<head>
	<style>
	
		.pc-popup{
			width:410px;margin-left:100px;
		}
		
		.model-title{
			line-height:30px;
			height:30px;
			margin-top:0px;
			padding-left:10px;
			background: #eee;
			color:#333;
		}
		
		.control-label{
			font-weight: normal;
		}
		
		.didiao{
			border:1px solid #ccc;
		}
		.outstanding{
			border:3px solid #ff5500;
		}
	</style>
</head>

<body>
	<tags:top/>
    <div class="container" style="margin-top:40px;">
    	<div class="row">
    		<div class="thumbnail" style="border:none;float: left;">
    			<a href="/login/" style="color:#ff5500">注册</a>
    			/   
    			<a href="/register/" style="color:#ff5500">登录</a>
    		</div>
    		
    	</div>
<!--     	<div style="color:#ff5500;padding-bottom:5px;">尊敬的顾客，登录后可以采用支付宝担保交易付款，让您购物更方便、安全、放心！<a href="#" style="color:#ff5500;" id="go_login_id">立即登录</a></div> -->
		<a name="consigneeFocus"></a>    	
    	<div class="row outstanding" id="addr_div_id" data-save="false">
    		<div class="col-md-12" style="padding:10px;">
    			<strong style="font-size:16px;">收货人信息</strong>
    		</div>
    		
    		<div class="col-md-12" style="padding-left:30px;">
    		
		      <div class="radio" id="address_addr_id" style="display: none;">
			  	<label>
				    <input type="radio" name="" id="optionsRadios1" value="option1" checked>
				    <span class="name-id" style="margin-right:5px;"></span>
				    <span class="addr-id" style="margin-right:5px;"></span>
				    <span class="mobile-id" style="margin-right:5px;"></span>
				    
				    <span><a href="#" id="edit_addr_a">修改</a></span>
			  	</label>
			   </div>	
				<form class="form-horizontal" role="form" id="addr_form">
  					 <div id="add_div">
					  <div class="form-group">
					    <label for="inputEmail3" class="col-sm-2 control-label">收货人：</label>
					    <div class="col-sm-10 col-md-2">
					      <input type="text" name="name" class="form-control useTitle required validate-chinese min-length-2 max-length-8" required-title="请输入收件人"  validate-chinese-title="请输入您真实的姓名"  min-length-title="请输入您真实的姓名" max-length-title="请输入您真实的姓名"/>
					    </div>
					  </div>
					    <div class="form-group">
						    <label for="inputPassword3" class="col-sm-2 col-md-2 control-label">所在地区：</label>
						   
						    <div class="col-sm-8 col-md-6">
							  <div class="col-xs-4 col-sm-4" style="padding-left:0px;">
							  	<select class="form-control required" name="province" id="province_sel">
							  		<option value="">请选择</option>
							  	</select>
							  	
							  </div>
							  <div class="col-xs-4 col-sm-4"  style="padding-left:0px;">
							    <select class="form-control required"  name="city" id="city_sel">
							  		<option value="">请选择</option>
							  	</select>
							  </div>
							  <div class="col-xs-4 col-sm-4" style="padding-left:0px;">
							    <select class="form-control required" name="area" id="area_sel">
							  		<option value="">请选择</option>
							  	</select>
							  </div>
							</div>
						  </div>
					  
					  <div class="form-group">
					    <label for="" class="col-sm-2 col-md-2 control-label">详细地址：</label>
					    <div class="col-sm-10 col-md-5">
					      <input type="text" name="address" placeholder="详细地址无需在填写省、市、区" id="" class="form-control required  min-length-6 max-length-120 useTitle" required-title="请填写详细地址" min-length-title="请填写详细地址" max-length="不能超过120个字符">
					    </div>
					  </div>
					  
				     <div class="form-group">
					    <label for="" class="col-sm-2 col-md-2 control-label">手机号码：</label>
					    <div class="col-sm-10 col-md-5">
					     <div class="col-sm-7" style="padding-left:0px;">
						  	<input type="text" name="mobile" id="" required-title="请输入手机号码" validate-mobile-phone-title="手机号码不正确"  class="form-control useTitle required validate-mobile-phone">
						  </div>
						  
<!-- 						 <div class="col-sm-5" style="padding-left:0px;"> -->
<!-- 						 	<button type="submit" class="btn btn-def">获取验证码</button> -->
<!-- 						 </div> -->
					     
					    </div>
					     
					  </div>
					  
<!-- 					  <div class="form-group"> -->
<!-- 					    <label for="inputPassword3" class="col-sm-2 control-label">短信验证码：</label> -->
<!-- 					    <div class="col-md-2"> -->
<!-- 					      <input type="password" class="form-control" id="inputPassword3" > -->
<!-- 					    </div> -->
<!-- 					  </div> -->

					
					  
					  <div class="form-group">
					    <div class="col-sm-offset-2 col-md-5">
					      <button type="button" id="save_addr_btn" class="btn btn-buy">保存收货人信息</button>
					    </div>
					  </div>
					 </div>
				</form>
			</div>
				
    	</div>
    	
   		
   		<div id="pay_div_id" style="margin-top:40px;" class="row didiao" data-save="false">
    		<div class="col-md-12" style="padding:10px;">
    			<strong style="font-size:16px;">支付及配送方式</strong>
    			<span style="font-size:13px;color:#666;"><a href="#orderremarka" class="orderremark-css" style="color:#ff5500;">（如有特殊要求请订单附言）</a></span>
    			
    			<div style="padding-left:20px;margin-top:20px;" id="pay_type_id">
    			
    			<div class="radio">
					  	<label>
						    <input type="radio" name="payType" id="" value="0"  checked="checked">
						           <span style="font-weight: bold;">货到付款：</span>我们会安排顺丰快递为您派送，先验货在付款，安全又放心！
					  	</label>
					</div>
    			
    				<div class="radio" style="display: none;">
					  	<label>
						    <input type="radio" name="payType" id="" value="1" >
						           <span style="font-weight: bold;">支付宝担保交易付款：</span>（<span style="color:#ff5500;">支付宝付款立减5元</span>）和淘宝网购物一样的支付方式，先付款到支付宝，收到货满意后在确认收货，安全有保障！
					  	</label>
					</div>
					
	    			
					
<!-- 					<div class="radio"> -->
<!-- 					  	<label> -->
<!-- 						    <input type="radio" name="payType" id="" value="1"/> -->
<!-- 						           支付宝担保付款 -->
<!-- 					  	</label> -->
<!-- 					</div> -->
					
    			</div>
    		</div>
    		
   		</div>
    	
    	<div class="row" style="border:1px solid #ccc;margin-top:40px;">
    		
	    		<ul class="list-group" style="border:none;margin-bottom:0px;padding-bottom:0px;">
	    			<li class="list-group-item">
	    				<strong style="font-size:16px;">商品清单</strong>
	    			</li>
				  <li class="list-group-item" style="background: #F7F7F7;">
				  	<div class="row">
				  		<div class="col-xs-4 col-md-4" align="center">商品</div>
				  		<div class="col-xs-4 col-md-3" align="center">价格</div>
				  		<div class="col-xs-4 col-md-3" align="center">数量</div>
				  	</div>
				  
				  </li>
				  <div class="shopboxs">
					  <li class="list-group-item" id="cart_model_div" style="display: none;margin-top:1px;">
					  	<h5><a href="#" style="font-size:12px; " class="title"></a></h5>
					  	<h5 style="font-size:12px;color:#666;" id="color_size_id"></h5>
					  	<div class="row">
					  		<div class="col-xs-4 col-md-4">
			  					 <img class="shoppic" alt="" src="" style="width:60px;height:60px;">
					  		</div>
					  		<div class="col-xs-4 col-md-3" align="center">
					  			<span class="price" style="color:#333;line-height: 60px;"></span>
					  		</div>
					  		
					  		<div class="col-xs-4 col-md-3" align="center">
					  			<span class="num" style="color:#333;line-height: 60px;"></span>
					  		</div>
					  	</div>
					  </li>
				  </div>
				  
				   <li class="list-group-item" style="background: #F7F7F7;border-bottom:none;">
				   	
				   	  <div class="total fr" align="right">商品总计：<span class="totalPrice" style="color: #666;font-size: 14px;font-weight: 400;" data-bind="0.00">¥0.00</span></div>
				   	  <div class="total fr" align="right">运费：<span class="express" style="color: #666;font-size: 14px;font-weight: 400;" data-bind="0.00">¥0.00</span></div>
				   	  <div class="total fr" align="right">总计（包邮免运费）：<span class="finalPrice" style="color: #F76120;font-size: 20px;font-weight: 400;" data-bind="0.00">¥0.00</span></div>
				   </li>
				   
				   
			 
			</ul>
		
    	</div>
    	
    	<a name="orderremarka"></a>
    	<div class="row" style="margin-top:15px;" >
    		<div class="col-md-12">
		    	<form class="form-horizontal" role="form">
				  <div class="form-group">
				    <label for="inputEmail3" class="col-md-2 control-label">订单附言：</label>
				    <div class="col-md-10">
				      <textarea id="remark_id" style="height:60px;" class="form-control"></textarea>
				    </div>
				  </div>
				</form>
			</div>
		</div>
    	<div class="row" style="margin-top:10px;" id="submit_tips">
    		<div style="float:right;height:30px;line-height: 30px;padding:0px 5px;color:#F60;font-size:12px;background-color: #FFFDEE;border: 1px solid #EDD28B;" id="tips_error">您需先保存<a href="#consigneeFocus" id="tips_miao">收货人信息</a>,在提交订单</div>
    	</div>
    	
    	<div class="row" style="margin-top:5px;" >
    		<a class="btn btn-lg btn-def" href="${ctx }/cart">返回购物车修改</a>
	    	<button disabled="disabled" type="button" id="submit_btn"  class="btn btn-lg btn-buy disabled" href="${ctx }/settlement" style="float:right;margin-right:5px;">提交订单</button>
		</div>
		
		
  	</div>
  	
  	<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">确认订单</h4>
      </div>
      <div class="modal-body"  style="padding-bottom:60px;">
      
      <div class="row didiao" id="addr_div_id" data-save="false">
    		<div class="col-md-12" style="padding:10px;">
    			<strong style="font-size:16px;">收货人信息</strong>
    		</div>
    		
    		<div class="col-md-12" style="padding-left:30px;">
		         <div class="radio">
				  	<label>
					    <input type="radio" name="" id="optionsRadios1" value="option1" checked>
					    <span class="name-id" style="margin-right:5px;"></span>
					    <span class="addr-id" style="margin-right:5px;"></span>
					    <span class="mobile-id" style="margin-right:5px;"></span>
				  	</label>
			   </div>	
			</div>
 
      </div>
      
      <div id="" style="margin-top:10px;" class="row didiao" data-save="false">
    		<div class="col-md-12" style="padding:10px;">
    			<strong style="font-size:16px;">支付及配送方式</strong>
    			<span style="font-size:13px;color:#666;">（如有疑问请联系我们客服人员）</span>
    			
    			<div style="padding-left:20px;margin-top:20px;" id="model_pay_type_div">
	    			<div class="radio" style="display: none" id="zhifubaofukuan_id">
						  	<label>
							    <input type="radio" name="" id="" value="1" checked="checked">
							           <span style="font-weight: bold;">支付宝担保交易付款：</span>和淘宝网购物一样的支付方式，先付款到支付宝，收到货满意后在确认收货，安全有保障！
						  	</label>
					</div>
					
	    			<div class="radio" style="display: none" id="huodaofukuan_id">
					  	<label>
						    <input type="radio" name="" id="" value="0" checked="checked">
						           <span style="font-weight: bold;">货到付款：</span>我们会安排顺丰快递为您派送，先验货在付款，安全又放心！
					  	</label>
					</div>
					
    			</div>
    		</div>
    		
   		</div>
   		
   		<div class="total fr" align="right">商品总计：<span class="totalPrice" style="color: #666;font-size: 14px;font-weight: 400;" data-bind="0.00">¥0.00</span></div>
   	    <div class="total fr" align="right">运费：<span class="express" style="color: #666;font-size: 14px;font-weight: 400;" data-bind="0.00">¥0.00</span></div>
   		<div class="total fr" align="right">总计：<span class="finalPrice" style="color: #F76120;font-size: 20px;font-weight: 400;" data-bind="0.00">¥0.00</span></div>
   		
   		<div class="row" style="line-height: 20px;color:#F60;padding:4px; font-size:12px;background-color: #FFFDEE;border: 1px solid #EDD28B;">
   			尊敬的客户，提交订单后我们客服会短信跟您确认订单，请注意查收和回复，由于订单量比较大，订单确认后我们会在48小时内发货，请勿催单，为您带来的不便请您谅解！
   		</div>
   		
   		<div style="margin-top:10px;">
   			<button type="button" id="confirm_order_btn" class="btn btn-buy">确认订单</button>
   			<button type="buttom" class="btn btn-default" data-dismiss="modal">返回修改</button>
   		</div>
      
      </div>
      
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<!-- Modal -->
<div class="modal fade" id="login_modal_id" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content" style="margin-top:100px;">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">您尚未登录
        </h4>
      </div>
      <div class="modal-body">
        <div class="bs-example bs-example-tabs">
				      <ul id="myTab" class="nav nav-tabs">
				        <li class="active"><a href="#profile" data-toggle="tab">登录</a></li>
				        <li class=""><a href="#dropdown1" data-toggle="tab">注册</a></li>
				      </ul>
				      <div id="myTabContent" class="tab-content">
				        <div class="tab-pane fade active in" id="profile">
				          	<form role="form" id="login_form" style="padding-top:20px;">
							  <div class="form-group">
							    <label for="exampleInputEmail1">邮箱地址：</label>
							    <input type="text" name="email" class="form-control required useTitle validate-email" required-title="请输入用户名" id="email_login" placeholder="请输入邮箱">
							  </div>
							  <div class="form-group">
							    <label for="exampleInputPassword1">密码：</label>
							    <input type="password" name="password" class="form-control required useTitle min-length-6 max-length-16 ajax" maxlength="16" required-title="密码不能为空" min-length-title="密码由6到16位的字符组成" max-length-title="密码由6到16位的字符组成" id="password"/>
							  </div>
							   
							  <button type="submit" id="login_btn" class="btn btn-buy  btn-block" style="height:38px;">登录</button>
							  
<!-- 							   <div style="margin-top:5px;font-size:12px;"> -->
<%-- 							   		我不想登录<a style="color:#2DB8AD;" href="${ctx}/settlement">直接购买</a> --%>
<!-- 							   </div> -->
							</form>
				        </div>
				        <div class="tab-pane fade" id="dropdown1">
				          <form role="form" id="register_form" style="padding-top:20px;">
							  <div class="form-group">
							    <label for="exampleInputEmail1">电子邮箱：</label> 
							    <input type="text" name="email" class="form-control required useTitle validate-email ajax" required-title="请输入有效的电子邮箱" id="email_reg" placeholder="请输入电子邮箱作为账户名">
							  </div>
							  <div class="form-group">
							    <label for="exampleInputPassword1">密码：</label>
							    <input type="password" name="password" class="form-control required useTitle min-length-6 max-length-16" maxlength="16" required-title="密码不能为空" min-length-title="密码由6到16位的字符组成" max-length-title="密码由6到16位的字符组成" id="reg_password"/>
							  </div>
							  
							  <div class="form-group">
							    <label for="exampleInputPassword1">确认密码：</label>
							    <input type="password" name="confirmpassword" class="form-control required equals-reg_password useTitle min-length-6 max-length-16" maxlength="16" required-title="密码不能为空" min-length-title="密码由6到16位的字符组成" max-length-title="密码由6到16位的字符组成" id="confirmpassword"/>
							  </div>
							  
							   <div class="checkbox">
								    <label style="font-size:12px;">
								      <input type="checkbox" id="agree_ment_id"> 我已阅读并同意《<a style="color:#ff5500;" href="${ctx }/agreement" target="_blank">永乐运动鞋城用户注册协议</a>》
								    </label>
							   </div>
							  <button type="submit" id="register_btn" disabled="disabled" class="disabled btn btn-buy  btn-block" style="height:38px;">立即注册</button>
							  
<!-- 							   <div style="margin-top:5px;font-size:12px;"> -->
<%-- 							   		我不想注册<a style="color:#2DB8AD;" href="${ctx}/settlement">直接购买</a> --%>
<!-- 							   </div> -->
							</form>
				        </div>
				      </div>
			    </div>
 
      </div>
      
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
	
	<tags:bottom/>
	<script>
		$(function(){
			var valid = new jValidation.Validation('addr_form', {
				immediate : true
			});
			
			
			jQuery.ajax({
				type : 'Get',
				contentType : 'application/json',
				url : '${ctx}/address/getAll.do',
				dataType : 'json',
				async:false,
				success : function(data) {
					if (data.result) {
						var provinceList = data.obj;
						var proHtml = '<option value="">请选择</option>';
						for(var i = 0;i<provinceList.length;i++){
							var item = provinceList[i];
							proHtml = proHtml +'<option value="'+item.code+"|"+item.name+'">'+item.name+'</option>';
						}
						$("#province_sel").html(proHtml);
					} else {
						
					}
				},
				error : function(data) {
					 
				}
			});
			
			$("#province_sel").change(function(){
				var provincecode = $(this).val().split("|")[0];
				jQuery.ajax({
					type : 'Get',
					contentType : 'application/json',
					url : '${ctx}/address/getByProvincecode.do',
					dataType : 'json',
					async:false,
					data:{
						provincecode:provincecode
					},
					success : function(data) {
						if (data.result) {
							var cityList = data.obj;
							var proHtml = '<option value="">请选择</option>';
							for(var i = 0;i<cityList.length;i++){
								var item = cityList[i];
								proHtml = proHtml +'<option value="'+item.code+"|"+item.name+'">'+item.name+'</option>';
							}
							$("#city_sel").html(proHtml);
						} else {
							
						}
					},
					error : function(data) {
						 
					}
				});
			});
			
			$("#city_sel").change(function(){
				var citycode = $(this).val().split("|")[0];
				jQuery.ajax({
					type : 'Get',
					contentType : 'application/json',
					url : '${ctx}/address/getByCitycode.do',
					dataType : 'json',
					data:{
						citycode:citycode
					},
					async:false,
					success : function(data) {
						if (data.result) {
							var cityList = data.obj;
							var proHtml = '<option value="">请选择</option>';
							for(var i = 0;i<cityList.length;i++){
								var item = cityList[i];
								proHtml = proHtml +'<option value="'+item.code+"|"+item.name+'">'+item.name+'</option>';
							}
							$("#area_sel").html(proHtml);
						} else {
							
						}
					},
					error : function(data) {
						 
					}
				});
				
			});
			
			$("#save_addr_btn").click(function(){
				
				if(!valid.validate()){
					return false;
				}
				var postData = $("#addr_form").serialize();
				jQuery.ajax({
					type : 'POST',
					url : '${ctx}/customer/addAddr.do',
					dataType : 'json',
					data:postData,
					async:false,
					success : function(data) {
						if(data.result){
							var customerAddr = data.obj;
							$(".addr-id").each(function(){
								$(this).html(customerAddr.province+customerAddr.city+customerAddr.area+customerAddr.address);
							});
							$(".name-id").each(function(){
								$(this).html(customerAddr.name);
							});
							$(".mobile-id").each(function(){
								$(this).html(customerAddr.mobile);
							});
							$("#address_addr_id").show();
							$("#add_div").hide();
							$("#addr_div_id").removeClass("outstanding").addClass("didiao");
							//状态设置为已经保存地址，用于提交订单验证
							$("#addr_div_id").data("save",true);
							$("#submit_tips").hide();
							$("#submit_btn").prop("disabled",false).removeClass("disabled");
						}
					}
				});
				
				
			});
			
			//修改地址按钮
			$("#edit_addr_a").click(function(){
				$("#add_div").show();
				$("#addr_div_id").removeClass("didiao").addClass("outstanding");
				//状态设置为已经未保存地址，用于提交订单验证
				$("#addr_div_id").data("save",false);
				$("#submit_tips").show();
				$("#submit_btn").prop("disabled",true).addClass("disabled");
				return false;
			});
			
			//计算总价
			var calTotalPrice = function (){
				var totalPrice = 0;
				var payNum = 0;
				$(".shopboxs .price").each(function(){
					var price = $(this).data("price");
					if(price){
						totalPrice = totalPrice + parseFloat(price);
					}
					payNum++;
				});
				
				$(".totalPrice").each(function(){
					$(this).html("￥"+totalPrice);
				});
			
				$(".finalPrice").each(function(){
						$(this).html("￥"+totalPrice).data("totalPrice",totalPrice).data("srcTotalPrice",totalPrice);	
				});
				//$(".payinfo .fz12").html(payNum);
			};
			
			//获取购物车数据
			jQuery.ajax({
				type : 'Get',
				contentType : 'application/json',
				url : '${ctx}/cart/getCartList.do',
				async:false,
				dataType : 'json',
				success : function(data) {
					var cartList = data.obj;
					if(cartList){
						var modelDiv = $("#cart_model_div");
						for(var i=0 ;i<cartList.length;i++){
							var goods = cartList[i].goods;
							var num = cartList[i].num;
							var color = cartList[i].color;
							var size = cartList[i].size;
							var pic = cartList[i].pic;
							var model = modelDiv.clone();
							$(".shopboxs").append(model);
						    model.find(".title").attr("href","./detailGoods/"+goods.id);
						    model.find("#color_size_id").html("颜色："+color+"，尺码："+size);
							model.find(".title").html(goods.title);
							model.find(".shoppic").attr("src","./upload/download.do?fileName="+ pic);
							model.find(".num").html(num);
							var nowPrice = 0;
							for(var n = 0;n<num;n++){
								nowPrice = nowPrice +goods.nowPrice;
							}
							model.find(".price").html("¥"+nowPrice).data("price",nowPrice);
							model.find(".del").data("id",goods.id);
							model.show();
						}
						
						calTotalPrice();
						
					}else{
						alert("购物车为空！");
					}
					
				}
			});
			
			
			//提交订单按钮
			$("#submit_btn").click(function(){
				
				//回复置灰确认按钮，防止表单重复提交
				$("#confirm_order_btn").prop("disabled",false).removeClass("disabled");
				//选择支付方式
				var val = $("#pay_type_id :radio:checked").eq(0).val();
				
				$("#myModal #model_pay_type_div .radio").each(function(){
					$(this).hide();
				});
				
				if(val == 0){
					$("#huodaofukuan_id").show();
					$("#zhifubaofukuan_id").hide();
				}else{
					$("#zhifubaofukuan_id").show();
					$("#huodaofukuan_id").hide();
				}
				
				$('#myModal').modal();
				return false;
			});
			
			//确认订单按钮
			$("#confirm_order_btn").click(function(){
				var payType = $("#pay_type_id :radio:checked").eq(0).val();
				//置灰确认按钮，防止表单重复提交
				$("#confirm_order_btn").prop("disabled",true).addClass("disabled");
				//货到付款方式
				if(payType == 0){
					jQuery.ajax({
						type : 'POST',
						url : '${ctx}/order/add.do',
						data:{
							totalPrice:$(".finalPrice").eq(0).data("totalPrice"),
							remark:$("#remark_id").val(),
							payType:payType,
							host:window.location.host
						},
						dataType : 'json',
						async:false,
						success : function(data) {
								if(data.result){
									var order = data.obj;
									window.location.href = "${ctx}/order/orderSuccess/"+order.outerid;						
								}else{
									alert(data.errorMsg);
								}
						}			
					});
				//支付宝付款方式	
				}else{
					$("body").load('${ctx}/order/add.do',{
						totalPrice:$(".finalPrice").eq(0).data("totalPrice"),
						remark:$("#remark_id").val(),
						payType:payType
					},function(){
						
					});
				}
			});
			
			//如有特殊要求请订单附言
			$(".orderremark-css").click(function(){
				$('#myModal').modal('hide');
				$("#remark_id").focus();
			});
			
			//立即登录click事件
			$("#go_login_id").click(function(){
				$('#login_modal_id').modal();
				return false;
			});
			
			
			var validLogin = new jValidation.Validation('login_form', {
				immediate : true,
				onElementValidateForAjax : function(elm) {
					if ($(elm).attr("id") == 'password') {
						var password = $("#password").val();
						var username = $("#email_login").val();
						return validateUser(username,password);
					}
				}
				
			});
			
			var validReg = new jValidation.Validation('register_form', {
				immediate : true,
				onElementValidateForAjax : function(elm) {
					if ($(elm).attr("id") == 'email_reg') {
						var username = $(elm).val();
						return validateUsername(username);
					}
				}
			});
			
			function validateUser(username,password) {
				var result = new jValidation.ajax.Result();
				jQuery.ajax({
					type : 'Get',
					contentType : 'application/json',
					url : '${ctx}/customer/validate.do',
					dataType : 'json',
					async : false,
					data : {
						username : username,
						password:password
					},
					success : function(data) {
						if (!data.result) {
							result.setResult(false);
							result.setErrorMsg(data.errorMsg);
						} else {
							result.setResult(true);
						}
					},
					error : function(data) {
						result.setResult(false);
						result.setErrorMsg("服务器繁忙，请您稍后再试！");
					}
				});
				return result;

			}
			
			function validateUsername(username) {
				var result = new jValidation.ajax.Result();
				jQuery.ajax({
					type : 'Get',
					contentType : 'application/json',
					url : '${ctx}/customer/validateUsername.do',
					dataType : 'json',
					async : false,
					data : {
						username : username
					},
					success : function(data) {
						if (!data.result) {
							result.setResult(false);
							result.setErrorMsg(data.errorMsg);
						} else {
							result.setResult(true);
						}
					},
					error : function(data) {
						result.setResult(false);
						result.setErrorMsg("服务器繁忙，请您稍后再试！");
					}
				});
				return result;

			}
			
			$('#myTab a').click(function (e) {
				  e.preventDefault();
				  $(this).tab('show');
			});
			
			$("#login_btn").click(function(){
				if(!validLogin.validate()){
					return false;
				}
				window.location.href = "${ctx}/settlementLogined";
				return false;
			});
			
			$("#register_btn").click(function(){
				if(!validReg.validate()){
					return false;
				}
				
				var postData = $("#register_form").serialize();

				$.ajax({
					type : "POST",
					url : "${ctx}/customer/add.do",
					data : postData,
					dataType : "json",
					success : function(data) {
						if (data.result) {
							window.location.href = "${ctx}/settlementLogined";
						} else {
							alert("系统繁忙，请您稍后再试！");
							return false;
						}
					},
					error : function(data) {
						alert("系统繁忙，请您稍后再试！");
						return false;
					}
				});
				return false;
			});
			
			//同意协议复选框绑定事件
			$("#agree_ment_id").click(function(){
				
				if($(this).prop("checked")){
					$("#register_btn").removeClass("disabled").prop("disabled",false);
				}else{
					$("#register_btn").addClass("disabled").prop("disabled",true);
				}
			});
			
			//如果是PC端，设置popup宽度
			if(jWei.util.isPC()){
				$(".modal-content").addClass("pc-popup");
			}
			
			//设置支付宝下单立减5元
			$("#pay_type_id :radio").each(function(){
				var srcTotalPrice = $(".finalPrice").eq(0).data("srcTotalPrice");
				$(this).click(function(){
					var val = $("#pay_type_id :radio:checked").val();
					//货到付款
					if(val == 0){
						$(".finalPrice").each(function(){
							$(this).html("￥"+srcTotalPrice).data("totalPrice",srcTotalPrice);	
						});
						$(".express").each(function(){
							$(this).html("￥0.00");
						});
					//支付宝付款
					}else if(val == 1){
						var totalPrice = srcTotalPrice -5;
						$(".finalPrice").each(function(){
							$(this).html("￥"+totalPrice).data("totalPrice",totalPrice);	
						});
						$(".express").each(function(){
							$(this).html("￥-5.00");
						});
					}	
					
				});
			});
			
		});
	</script>
	
</body>